home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / mdm-2.000 / mdm-2 / flog.c < prev    next >
C/C++ Source or Header  |  1993-10-10  |  4KB  |  141 lines

  1. /*************************************************************************
  2. General Logging routine
  3. --------------------------------------------------------------------------
  4.  
  5.     Copyright (C) 1992  Anthony Rumble
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 1, or
  10.     any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details. <copying>
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. --------------------------------------------------------------------------
  22. RCS Info
  23.  
  24. $Header: /home/smilie/bbs/modem/RCS/flog.c,v 1.7 1992/10/09 14:47:07 smilie Exp $
  25.  
  26. $Log: flog.c,v $
  27.  * Revision 1.7  1992/10/09  14:47:07  smilie
  28.  * fixed a small problem
  29.  *
  30.  * Revision 1.6  1992/10/09  14:41:31  smilie
  31.  * *** empty log message ***
  32.  *
  33.  * Revision 1.5  1992/10/09  14:38:57  smilie
  34.  * fixed logging
  35.  *
  36.  * Revision 1.4  1992/10/09  13:48:02  smilie
  37.  * fixed another warning up
  38.  *
  39.  * Revision 1.3  1992/10/09  13:42:43  smilie
  40.  * fixed some warnings
  41.  *
  42.  * Revision 1.2  1992/10/09  13:18:11  smilie
  43.  * fixed a few things
  44.  *
  45.  * Revision 1.1  1992/10/09  12:16:08  smilie
  46.  * Initial revision
  47.  *
  48.  
  49. *************************************************************************/
  50.  
  51. /* Feature test switches */
  52. #define _POSIX_SOURCE 1
  53. #define _FLOG_C
  54.  
  55. /* System Headers */
  56. #include <stdio.h>        /* STD I/O header */
  57. #include <stdarg.h>        /* STD Argument header */
  58. #include <time.h>        /* Time function header */
  59. #include <errno.h>
  60.  
  61. /* Local Headers */
  62.  
  63. /* Macros */
  64.  
  65. /* File scope variables */
  66.  
  67. static char flog_rcsid[] = "$Id: flog.c,v 1.7 1992/10/09 14:47:07 smilie Exp $";
  68. #define RCSID flog_rcsid
  69.  
  70. /* External variables */
  71.  
  72. extern char stty[8];        /* Short TTY name */
  73.  
  74. /* External Functions */
  75.  
  76. /* Structures and unions */
  77.  
  78. /* Functions */
  79.  
  80. /************************************************************************
  81.                 FLOG
  82. -------------------------------------------------------------------------
  83. General LOGGING function, works similar to printf
  84. *************************************************************************/
  85. void flog(char *fmt, ...)
  86. {
  87. va_list    ap;        /* Variable List */
  88. #if defined(LOGFILE) || defined(LOGDEV)
  89. FILE *fh;
  90. #endif
  91. time_t t;
  92. struct tm *lt;
  93. char tmps[256];
  94. /**/
  95.  
  96. (void)time(&t);            /* Get Current TIme */
  97. lt = localtime(&t);        /* Put time into structure */
  98.  
  99. (void)strftime(tmps, sizeof(tmps), "%H:%M", lt);
  100.  
  101. #ifdef LOGDEV
  102. if ((fh = fopen(LOGDEV, "w")) ==  NULL)
  103.     {
  104.     (void)fprintf(stderr, "flog: Cannot open logdevice\n");
  105.     perror("logfile");
  106.     (void)exit(1);
  107.     }
  108.     
  109. (void)fprintf(fh, "%s %s ", stty, tmps);
  110. va_start(ap, fmt);        /* Open Argument list */
  111. vfprintf(fh, fmt, ap);        /* Print to STD error */
  112. va_end(ap);            /* Close Argument list */
  113. (void)fclose(fh);
  114. #else
  115. (void)fprintf(stderr, "%s %s ", stty, tmps);
  116. va_start(ap, fmt);        /* Open Argument list */
  117. vfprintf(stderr, fmt, ap);    /* Print to STD error */
  118. va_end(ap);            /* Close Argument list */
  119. #endif
  120.  
  121. #ifdef LOGFILE
  122. if ((fh = fopen(LOGFILE, "at")) ==  NULL)
  123.     {
  124.     (void)fprintf(stderr, "flog: Cannot open logfile\n");
  125.     perror("logfile");
  126.     (void)exit(1);
  127.     }
  128.  
  129. (void)strftime(tmps, sizeof(tmps), "%c", lt);
  130.  
  131. (void)fprintf(fh, "%s %s ", stty, tmps);
  132. va_start(ap, fmt);
  133. vfprintf(fh, fmt, ap);
  134. va_end(ap);
  135. (void)fclose(fh);
  136. #endif
  137. }
  138.  
  139.  
  140.  
  141.